package com.decent.web.index;

import com.decent.common.annotation.RequestRateLimiter;
import com.decent.common.bo.SimpleMessage;
import com.decent.common.enums.ErrorCodeEnum;
import org.redisson.api.RateIntervalUnit;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * RedissionController
 *
 * @author wangyan
 **/
@RestController
@RequestMapping("/redission/limit")
public class RedissionController {

    /**
     * 为方便测试，每两秒生成一个限流令牌
     *
     * @return String
     */
    @RequestMapping("/add")
    @RequestRateLimiter(key = "test", rate = 2, rateInterval = 2, timeUnit = RateIntervalUnit.SECONDS)
    public SimpleMessage add() {
        return new SimpleMessage(ErrorCodeEnum.OK);
    }
}
